%用于确定每条边对应在邻居处的点值
function neighbor_rf_nodes = find_rf_nodes_lrbd(tri, lr_re, x_inter)
%先处理左右边界的
neighbor_rf_nodes = zeros(4,2,2); %每条边有四个高斯点,对应两个边界
lc = lr_re(1);
ls = lr_re(2);
rc = lr_re(3);
rs = lr_re(4);
%处理左边界
lc_gauss_nodes = tri(lc).edge_gauss(:,:,ls);
%rf_gauss_nodes = zeros(size(lc_gauss_nodes,[1,2]));
rf_gauss_nodes = lc_gauss_nodes;
rf_gauss_nodes(:,1) = x_inter(2);
%处理右边界
rc_gauss_nodes = tri(rc).edge_gauss(:,:,rs);
lf_gauss_nodes = rc_gauss_nodes;
lf_gauss_nodes(:,1) = x_inter(1);
for j = 1 : size(rf_gauss_nodes,1)
    tmp_rf_nodes = get_nodes(tri(rc).nodes, rf_gauss_nodes(j,:));
    tmp_lf_nodes = get_nodes(tri(lc).nodes, lf_gauss_nodes(j,:));
    neighbor_rf_nodes(j,:,1) = tmp_rf_nodes;
    neighbor_rf_nodes(j,:,2) = tmp_lf_nodes;
end
end

function edge_rf_nodes = get_nodes(nodes, edge_gauss)
%edge_rf_nodes = zeros(size(edge_gauss));
%edge_gauss: 物理单元坐标
%edge_rf_nodes: 参考单元坐标
Jacobi = [-nodes(1,1)+nodes(2,1), nodes(3,1) - nodes(1,1);
    -nodes(1,2)+nodes(2,2), nodes(3,2) - nodes(1,2)];
for i = 1 : 3
    for j = 1 : 4
        x = edge_gauss(1);
        y = edge_gauss(2);
        b = [x- nodes(1,1);y-nodes(1,2)];
        edge_rf_nodes = Jacobi\b;
        % disp(tmp);
        % disp([xi,eta]);
    end
end
end